package {
	import flash.geom.Rectangle;
	import Print2Flash.*;
	
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.display.Stage;
	
	import org.papervision3d.events.InteractiveScene3DEvent;
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.materials.MovieMaterial;
	
	public class DocumentPolaroid extends Polaroid
	{
		private var swfHolder:Sprite;
		private var tmpMat:BitmapMaterial;
		private var tmpBitmapData:BitmapData;
		private var flashDoc:Print2FlashDoc;
		private var loaded:Boolean = false;
		private var documentMaterial:MovieMaterial;
		private var scrollPos:int = 0;
		private var zoomPos:int = 100;
		//private var s:Stage;
		
		public function DocumentPolaroid(){
			//this.s = _s;
			init();
		}
		
		private function init():void{
			
			swfHolder = new Sprite();
			
			flashDoc = new Print2FlashDoc("newsletter.swf",0,0,1000,1000,swfHolder);
			
			documentMaterial = new MovieMaterial(swfHolder,false,false,false,new Rectangle(0,0,1000,1000));
			contentPlane.material = documentMaterial;
			

			tmpBitmapData = new BitmapData(1000,1000,false);
			tmpMat = new BitmapMaterial(tmpBitmapData);
			tmpMat.interactive = true;	
			contentPlane.material = tmpMat;	
			
			
			this.enableUpdate();
			
			
			//s.addChild(swfHolder);
			//swfHolder.alpha = 0.1;
			//swfHolder.scaleX = 0.2;
			//swfHolder.scaleY= 0.2;
			//contentPlane.addEventListener( InteractiveScene3DEvent.OBJECT_MOVE, mMove);								
		}
		
		/*
		private function mMove( e:InteractiveScene3DEvent ):void {
			
         	swfHolder.x = (s.mouseX -e.x);
         	swfHolder.y = s.mouseY -e.y;

       }
		*/
		
		override public function update():void{	
			
			//Loader
			/*if(	this.flashDoc.loaderInfo.bytesLoaded == this.flashDoc.loaderInfo.bytesTotal
				&& loaded == false){
				loaded = true;
				this.flashDoc.setCurrentZoom(200);
			}*/
			//this.flashDoc.setCurrentZoom(200);
			
			tmpBitmapData.draw(swfHolder);
			tmpMat.updateBitmap();
			
			//documentMaterial.updateBitmap();	
		}
		
		override public function scroll(value:int,ctrlKey:Boolean):void {
			if(ctrlKey == false){
				if(scrollPos + value*-10 >= 0){
					scrollPos += value*-10;
					mmss_3D.txt.text = scrollPos.toString();
					this.flashDoc.setScrollPosition(new Point(0,scrollPos));
				}
			}
			else{
				zoomPos += value*-1;
				this.flashDoc.setCurrentZoom(zoomPos);
			}
		}
	}
}
